package sqlanalysisgui.view;

import org.apache.log4j.Logger;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.part.ViewPart;
import org.eclipse.zest.core.widgets.Graph;
import org.eclipse.zest.core.widgets.GraphConnection;
import org.eclipse.zest.core.widgets.GraphNode;
import org.eclipse.zest.layouts.LayoutStyles;
import org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm;

public class ZestView extends ViewPart {
	private Logger logger =  Logger.getLogger(this.getClass());
	public static final String ID = "sqlanalysisgui.view.ZestView"; //$NON-NLS-1$
	  private Graph graph;
	  private int layout = 1;

	public ZestView() {
	}

	/**
	 * Create contents of the view part.
	 * @param parent
	 */
	@Override
	public void createPartControl(Composite parent) {
//		Composite container = new Composite(parent, SWT.NONE);
		   // Graph will hold all other objects
		Display d = new Display();
		Shell shell = new Shell(d);
		shell.setText("GraphSnippet1");
		shell.setLayout(new FillLayout());
		shell.setSize(700, 400);
		Graph g = new Graph(shell, SWT.NONE);
		GraphNode n = new GraphNode(g, SWT.NONE, "Paper");
		GraphNode n2 = new GraphNode(g, SWT.NONE, "Rock");
		GraphNode n3 = new GraphNode(g, SWT.NONE, "Scissors");
		new GraphNode(g, SWT.NONE, "Scissors");
		new GraphNode(g, SWT.NONE, "Scissors");
		new GraphNode(g, SWT.NONE, "Scissors");
		new GraphNode(g, SWT.NONE, "Scissors");
		new GraphNode(g, SWT.NONE, "Scissors");
		new GraphConnection(g, SWT.NONE, n, n2);
		new GraphConnection(g, SWT.NONE, n2, n3);
		new GraphConnection(g, SWT.NONE, new GraphNode(g, SWT.NONE, "111"), new GraphNode(g, SWT.NONE, "2222"));
		new GraphConnection(g, SWT.NONE, new GraphNode(g, SWT.NONE, "111"), new GraphNode(g, SWT.NONE, "2222"));
		new GraphConnection(g, SWT.NONE, new GraphNode(g, SWT.NONE, "111"), new GraphNode(g, SWT.NONE, "2222"));
		new GraphConnection(g, SWT.NONE, new GraphNode(g, SWT.NONE, "111"), new GraphNode(g, SWT.NONE, "2222"));
		//new GraphConnection(g, SWT.NONE, n3, n);
		g.setLayoutAlgorithm(new SpringLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true);
		
/*	    graph = new Graph(parent, SWT.NONE);
	    // Now a few nodes
	    GraphNode node1 = new GraphNode(graph, SWT.NONE, "Jim");
	    GraphNode node2 = new GraphNode(graph, SWT.NONE, "Jack");
	    GraphNode node3 = new GraphNode(graph, SWT.NONE, "Joe");
	    GraphNode node4 = new GraphNode(graph, SWT.NONE, "Bill");
	    // Lets have a directed connection
	    new GraphConnection(graph, ZestStyles.CONNECTIONS_DIRECTED, node1,
	        node2);
	    // Lets have a dotted graph connection
	    new GraphConnection(graph, ZestStyles.CONNECTIONS_DOT, node2, node3);
	    // Standard connection
	    new GraphConnection(graph, SWT.NONE, node3, node1);
	    // Change line color and line width
	    GraphConnection graphConnection = new GraphConnection(graph, SWT.NONE,
	        node1, node4);
	    graphConnection.changeLineColor(parent.getDisplay().getSystemColor(SWT.COLOR_GREEN));
	    // Also set a text
	    graphConnection.setText("This is a text");
	    graphConnection.setHighlightColor(parent.getDisplay().getSystemColor(SWT.COLOR_RED));
	    graphConnection.setLineWidth(3);

	    graph.setLayoutAlgorithm(new SpringLayoutAlgorithm(LayoutStyles.NO_LAYOUT_NODE_RESIZING), true);
	    // Selection listener on graphConnect or GraphNode is not supported
	    // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=236528
	    graph.addSelectionListener(new SelectionAdapter() {
	      @Override
	      public void widgetSelected(SelectionEvent e) {
	        System.out.println(e);
	      }

	    });*/
		createActions();
		initializeToolBar();
		initializeMenu();
	}

	/**
	 * Create the actions.
	 */
	private void createActions() {
		// Create the actions
	}

	/**
	 * Initialize the toolbar.
	 */
	private void initializeToolBar() {
		IToolBarManager toolbarManager = getViewSite().getActionBars()
				.getToolBarManager();
	}

	/**
	 * Initialize the menu.
	 */
	private void initializeMenu() {
		IMenuManager menuManager = getViewSite().getActionBars()
				.getMenuManager();
	}

	@Override
	public void setFocus() {
		// Set the focus
	}

}
